﻿CREATE VIEW [acms].[PostControl_View]
AS 
	SELECT 
		c.Id,
		a.Id as PostId, 
		e.Id as PostVersionId, 
		b.Id as TemplateControlId, 
		b.Name, 
		b.TypeId,
		d.Name as TypeName,
		d.AdminControlType,
		c.Value,
		b.Notes,
		c.ConcurencyId
	FROM [acms].[Posts] a 
		inner join [acms].[PostVersions] e on a.Id = e.PostId
		inner join [acms].[TemplateControls] b on e.TemplateId = b.TemplateId
		inner join [acms].[ControlTypes] d on b.TypeId = d.Id
		left outer join [acms].[PostControls] c on c.TemplateControlId = b.Id and c.PostVersionId = e.Id and c.Deleted = 0
	Where a.Deleted = 0 and b.Deleted = 0 and d.Deleted = 0

			
;